//获取应用实例
const request = require('../../../../../utils/request');

Page({
    //初始化数据
    data: {
      money: ''
    },
    //获取链接参数
    onLoad: function (e){
        
    },
    onReady: function(){
        wx.setNavigationBarTitle({
            title: '充值中心'
        }) 
    },
    handleInput(e) {
        this.setData({
            money: Math.floor(e.detail.value*100)/100
        })
    },
    recharge() {
        request.HttpRequst(true,'onlineCharge',2,'',{"money":this.data.money,'token':wx.getStorageSync("sessionId")},"POST",false,res => {
            console.log(res);
            if(res.code == 200){
                request.HttpRequst(true,'pay',2,'',{"pay_way":'wechat', 'order_id':res.data.order_id, 'pay_port':'miniapp','payword':wx.getStorageSync("sessionId")},"POST",false,res => {
                    console.log(res);
                    if( res.code == '200') {
                        wx.requestPayment({
                            'timeStamp': res.data.timeStamp,
                            'nonceStr': res.data.nonceStr,
                            'package': res.data.package,
                            'signType': 'MD5',
                            'paySign': res.data.paySign,
                            'success':function(res){
                                console.log("支付成功")
                            },
                            'fail':function(res){
                                wx.showModal({
                                    title: '提示',
                                    content: res.info,
                                    showCancel: false
                                })
                            }
                        })
                    }else {
                        wx.showModal({
                            title: '提示',
                            content: res.info,
                            showCancel: false
                        })
                    } 
                })
            }else{
                wx.showModal({
                    title: '提示',
                    content: res.info,
                    showCancel: false
                })
            }
            
        })
    }

})